﻿///***************************************************************
/// 시  스  템 : Base
/// 단위시스템 : Dac
/// 계      층 : BaseProject Layer
/// 프로그램명 : Global
/// 파  일  명 : Global.cs
/// 설      명 : 글로벌 클래스
///***************************************************************
/// 수정ID 일자       이름     내용
///---------------------------------------------------------------
/// CH001  2008-07-18 송시명   최초 작성
///***************************************************************
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.EnterpriseServices;
using System.Runtime.InteropServices;



namespace Base.Dac
{
	[ComVisible(true)]
	[Transaction(TransactionOption.Supported)]
	[JustInTimeActivation(true)]
	public class Global : Base.AppFramework.DacBase
	{
		public Global()
		{
		}

		#region CheckSaveMode

		/// <summary>
		/// 테이블에서 PK값이 있는지 확인한다.(Save버튼 누르면)
		/// </summary>
		[AutoComplete]
		public bool CheckSaveMode(string arg_ls_table, string ls_field, string arg_ls_value)
		{
			bool lb_exist = false;

			string ls_sql = "SELECT COUNT(*) FROM " + arg_ls_table + " WHERE " + ls_field + " = '" + arg_ls_value + "'";

			int li_rslt = (int)_agent.ExecuteScalar(ls_sql);
			
			lb_exist = (li_rslt == 1) ? true : false;
			
			return lb_exist;
		}

		#endregion
		
		#region 프로그램명 조회
		
		/// <summary>
		/// 프로그램명 조회
		/// </summary>
		[AutoComplete]
		public string GetMenuTitle(string ls_pid, string ls_lang_set)
		{
			string ls_sql = "usp_UPDMS_COM_PGM_Get_Menu_Title";

			SqlParameter[] paramArray =
			{
				new SqlParameter("ls_pid", ls_pid),
				new SqlParameter("ls_lang_set", ls_lang_set)
			};

			return (string)_agent.ExecuteScalar(ls_sql, paramArray, CommandType.StoredProcedure);			
		}


		#endregion

		#region 메뉴 디렉토리 정보 조회
		/// <summary>
		/// 프로그램아이디로 메뉴 디렉토리 정보 조회
		/// </summary>
		[AutoComplete]
		public string GetDirDepth(string ls_pid)
		{
			string ls_sql = "usp_UPDMS_COM_PGM_Get_Dir_Depth";

			SqlParameter[] paramArray =
			{
				new SqlParameter("ls_pid", ls_pid)
			};

			return (string)_agent.ExecuteScalar(ls_sql, paramArray, CommandType.StoredProcedure);
		}

		#endregion
		
		#region 공통코드조회

		/// <summary>
		/// 공통코드조회 - 라벨없이
		/// </summary>
		[AutoComplete]
		public DataSet GetCommCd(string ls_id, string ls_cd, string ls_lang_set)
		{
			return GetCommCd(ls_id, ls_cd, ls_lang_set, "");
		}

		/// <summary>
		/// 공통코드조회 - 라벨포함
		/// </summary>
		[AutoComplete]
		public DataSet GetCommCd(string ls_id, string ls_cd, string ls_lang_set, string ls_label)
		{
			string ls_sql = "usp_UPDMS_COM_CD_Get_Cd_Value";

			SqlParameter[] paramArray =
			{
				new SqlParameter("ls_id", ls_id),
				new SqlParameter("ls_cd", ls_cd),
				new SqlParameter("ls_lang_set", ls_lang_set),
				new SqlParameter("ls_label", ls_label),
			};

			DataSet ds = new DataSet();
			return _agent.Fill(ls_sql, "UPDMS_COM_CD", ds, paramArray, CommandType.StoredProcedure);
		}
		
		#endregion

		#region 공통코드조회 - 어트리뷰트

		/// <summary>
		/// 공통코드조회 - 라벨없이
		/// </summary>
		[AutoComplete]
		public DataSet GetCommCdAttr(string ls_id, string ls_cd, string ls_lang_set, int li_attr_no)
		{
			return GetCommCdAttr(ls_id, ls_cd, ls_lang_set, "", li_attr_no);
		}

		/// <summary>
		/// 공통코드조회 - 라벨포함
		/// </summary>
		[AutoComplete]
		public DataSet GetCommCdAttr(string ls_id, string ls_cd, string ls_lang_set, string ls_label, int li_attr_no)
		{
			string ls_sql = "usp_UPDMS_COM_CD_Get_Cd_Value_By_Attr_No";

			SqlParameter[] paramArray =
			{
				new SqlParameter("ls_id", ls_id),
				new SqlParameter("ls_cd", ls_cd),
				new SqlParameter("ls_lang_set", ls_lang_set),
				new SqlParameter("ls_label", ls_label),
				new SqlParameter("li_attr_no", li_attr_no),
			};

			DataSet ds = new DataSet();
			return _agent.Fill(ls_sql, "UPDMS_COM_CD", ds, paramArray, CommandType.StoredProcedure);
		}

		#endregion
		
		#region 공통코드조회 - 상위코드로

		/// <summary>
		/// 공통코드조회 - 상위코드로
		/// </summary>
		[AutoComplete]
		public DataSet GetCommUCd(string ls_id, string ls_ucd, string ls_lang_set)
		{
			return GetCommUCd(ls_id, ls_ucd, ls_lang_set, "");
		}
		
		/// <summary>
		/// 공통코드조회 - 상위코드로
		/// </summary>
		[AutoComplete]
		public DataSet GetCommUCd(string ls_id, string ls_ucd, string ls_lang_set, string ls_label)
		{
			string ls_sql = "usp_UPDMS_COM_CD_Get_Cd_Value_By_U_Cd";

			SqlParameter[] paramArray =
			{
				new SqlParameter("ls_id", ls_id),
				new SqlParameter("ls_ucd", ls_ucd),
				new SqlParameter("ls_lang_set", ls_lang_set),
				new SqlParameter("ls_label", ls_label),
			};

			DataSet ds = new DataSet();
			return _agent.Fill(ls_sql, "UPDMS_COM_CD", ds, paramArray, CommandType.StoredProcedure);
		}
		
		
		
		#endregion 
		
		#region 자동완성용 쿼리

		[AutoComplete]
		public string[] GetSearchData(string prefixText, int count, string ls_table, string ls_field)
		{
			string ls_sql =
					" SELECT DISTINCT TOP " + count + " " + ls_field + " as Result_Data FROM " + ls_table + " " +
					"  WHERE " + ls_field + " LIKE '" + prefixText + "%'";

			DataSet ds = new DataSet();
			List<string> items = new List<string>(count);

			_agent.Fill(ls_sql, "UPDMS_SEARCH_DATA", ds, null, CommandType.Text);

			if (ds.Tables[0].Rows.Count > 0)
			{
				for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
				{
					items.Add(ds.Tables[0].Rows[i]["Result_Data"].ToString());
				}
			}

			return items.ToArray();
		}
		
		#endregion		

		#region 다국어 조회

		/// <summary>
		/// 프로그램별 라벨정보 조회
		/// </summary>
		/// <param name="lo_dp"></param>
		/// <returns></returns>
		[AutoComplete]
		public DataSet GetLabelInfoByPgmId(string pgmId, string langSet)
		{
			string ls_sql = "usp_UPDMS_COM_LABEL_Get_Label_Info_By_Pgm_Id";

			SqlParameter[] paramArray =
			{
				new SqlParameter("ls_pgm_id", pgmId),
				new SqlParameter("ls_lang_set", langSet)
			};

			DataSet ds = new DataSet();
			return _agent.Fill(ls_sql, "UPDMS_COM_LABEL", ds, paramArray, CommandType.StoredProcedure);
		}


		#endregion

		#region 그리드 컬럼 조회

		/// <summary>
		/// 그리드 컬럼 조회
		/// </summary>
		/// <param name="lo_dp"></param>
		/// <returns></returns>
		[AutoComplete]
		public DataSet GetColumnListByPgmId(string pgmId, string langSet)
		{
			string ls_sql = "usp_UPDMS_COM_PGM_GRID_COLUMN_Get_Column_List_By_Pgm_Id";

			SqlParameter[] paramArray =
			{
				new SqlParameter("ls_pgm_id", pgmId),
				new SqlParameter("ls_lang_set", langSet)
			};

			DataSet ds = new DataSet();
			return _agent.Fill(ls_sql, "UPDMS_COM_PGM_GRID_COLUMN", ds, paramArray, CommandType.StoredProcedure);
		}


		#endregion

		#region 테이블별 신규아이디 조회

		/// <summary>
		/// 테이블별 신규아이디 조회
		/// </summary>
		/// <param name="ps_table"></param>
		/// <param name="ps_column"></param>
		/// <param name="ps_prefix"></param>
		/// <param name="ps_digit"></param>
		/// <returns></returns>
		[AutoComplete]
		public string GetNewIdByTable(string ps_table, string ps_column, string ps_prefix, string ps_digit)
		{
			string ls_sql = "usp_UPDMS_COM_Get_New_Id_By_Table";

			SqlParameter[] paramArray =
			{
				new SqlParameter("ls_table", ps_table),
				new SqlParameter("ls_column", ps_column),
				new SqlParameter("ls_prefix", ps_prefix),
				new SqlParameter("ls_digit", ps_digit)
			};

			return (string)_agent.ExecuteScalar(ls_sql, paramArray, CommandType.StoredProcedure);
		}

		/// <summary>
		/// 테이블별 신규아이디 조회 - 기본자릿수는 3
		/// </summary>
		/// <param name="ps_table"></param>
		/// <param name="ps_column"></param>
		/// <param name="ps_prefix"></param>
		/// <returns></returns>
		[AutoComplete]
		public string GetNewIdByTable(string ps_table, string ps_column, string ps_prefix)
		{
			return GetNewIdByTable(ps_table, ps_column, ps_prefix, "3");
		}


		#endregion

		#region 시스템 설정값 조회

		/// <summary>
		/// 사용자별 시스템 설정값 조회
		/// </summary>
		/// <param name="ps_user_id"></param>
		/// <returns></returns>
		[AutoComplete]
		public DataSet GetSettingValueByUserId(string ps_user_id)
		{
			string ls_sql = "usp_UPDMS_CFG_SETTING_MGT_Get_Setting_Value_By_User_Id";

			SqlParameter[] paramArray =
			{
				new SqlParameter("ls_user_id", ps_user_id)
			};

			DataSet ds = new DataSet();
			return _agent.Fill(ls_sql, "UPDMS_CFG_SETTING_MGT", ds, paramArray, CommandType.StoredProcedure);
		}

		#endregion

		#region 라벨아이디(Seq)별 라벨명 조회

		/// <summary>
		/// 라벨아이디(Seq)별 라벨명 조회
		/// </summary>
		/// <param name="ps_seq"></param>
		/// <param name="ps_lang_set"></param>
		/// <returns></returns>
		[AutoComplete]
		public string GetLabelNmBySeq(int pi_seq, string ps_lang_set)
		{
			string ls_sql = "usp_UPDMS_COM_LABEL_Get_Label_Nm_By_Seq";

			SqlParameter[] paramArray =
			{
				new SqlParameter("li_seq", pi_seq),
				new SqlParameter("ls_lang_set", ps_lang_set)
			};

			return (string)_agent.ExecuteScalar(ls_sql, paramArray, CommandType.StoredProcedure);
		}

		#endregion

		#region 카드사용내역중 확인이 체크된 내역의 장소정보를 조회

		/// <summary>
		/// 카드사용내역중 확인이 체크된 내역의 장소정보를 조회
		/// </summary>
		/// <returns></returns>
		[AutoComplete]
		public DataSet GetCheckedMapInfo()
		{
			string ls_sql = "usp_UPDMS_CRD_ITEM_BIZ_Get_Checked_Map_Info";

			DataSet ds = new DataSet();
			return _agent.Fill(ls_sql, "UPDMS_CRD_ITEM_BIZ", ds, null, CommandType.StoredProcedure);
		}

		#endregion
	}
}
